#ifndef MODEL_FACTORIZATION_MACHINE_HEADER
#define MODEL_FACTORIZATION_MACHINE_HEADER
#include "model.hpp"
#include "def.hpp"
#include <vector>
#include <unordered_map>

using namespace std;

namespace Puza{
	typedef vector<double> latentfactor;

	class PuzaModelFM: public PuzaLFM{
	private:
		double Squared_Loss(double y_bar, double y);
		double Logistic_Loss(double y_bar, double y);
		double Huber_Loss(double y_bar, double y);
		void Squared_Gradients(double y_bar, PuzaRow r);
		void Logistic_Gradients(double y_bar, PuzaRow r);
		void Huber_Gradients(double y_bar, PuzaRow r);
		void Gradients(double temp, PuzaRow r);
	protected:
		vector<latentfactor> theta;
		vector<double> weights;
		double weight_0;
		virtual double Hypothesis(PuzaRow r);
		virtual double PointwiseLossFunction(double y_bar, double y);
		virtual void PointwiseSGD(double y_bar, PuzaRow r);
	public:
		~PuzaModelFM();
		PuzaModelFM();
	};
};

#endif
